<?php

use Carbon\Carbon;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class RolesTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run () {
        //默认角色
        $datas = [
            1 => [
                'name' => '超级管理员',
                'sort' => 9999,
                'created_at' => Carbon::now(),
                'all'=> 1
            ],
            2 => [
                'name' => '管理员',
                'sort' => 9998,
                'created_at' => Carbon::now(),
                'all'=> 2
            ],
            3 => [
                'name' => '审核员',
                'sort' => 9997,
                'created_at' => Carbon::now(),
                'all'=> 2
            ]
        ];
        for ($i = 1; $i <= 3; $i++) {
            $role = DB::table('roles')->where(['id' => $i])->first();
            if (!empty($role)) {
                //update
                $datas[$i]['updated_at'] = Carbon::now();
                DB::table('roles')->where(['id' => $i])->update($datas[$i]);
            }
            else {

                //add
                DB::table('roles')->insert($datas[$i]);
            }
        }
    }
}
